/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Grafik;

import java.util.Locale;
import javax.swing.*;
import ModulHåndtering.*;
import java.util.TimerTask;

/**
 *
 * @author Charles Thillemann Hemmingsen s122801
 */
public class MainSkærm extends javax.swing.JFrame {

    char[] kodeord;
    Butler butler = new Butler();

    /**
     * Creates new form NewJFrame
     */
    public MainSkærm() {
        initComponents();
        opsæt.setEjer(this);
        hovedPanel.setEjer(this);
        loginPanel.setEjer(this);
        oversigt.setEjer(this);
        indstilinger.setEjer(this);

        rykForest(opsæt);
    }

    public void rykForest(JPanel vindue) {
        //TODO Spørg om der findes en bedre løsning
        rykBagerst(opsæt);
        rykBagerst(hovedPanel);
        rykBagerst(loginPanel);
        rykBagerst(oversigt);
        rykBagerst(indstilinger);

        vindue.setVisible(true);
        panelLag.moveToFront(vindue);
    }

    public void rykBagerst(JPanel vindue) {
        vindue.setVisible(false);
        panelLag.moveToBack(vindue);
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelLag = new javax.swing.JLayeredPane();
        loginPanel = new Grafik.LoginPanel();
        opsæt = new Grafik.Opsæt();
        hovedPanel = new Grafik.HovedPanel();
        indstilinger = new Grafik.Indstilinger();
        oversigt = new Grafik.Oversigt();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SmartHome");

        panelLag.add(loginPanel);
        loginPanel.setBounds(0, 0, 500, 500);
        panelLag.setLayer(loginPanel, 9);
        loginPanel.setVisible(false);
        panelLag.add(opsæt);
        opsæt.setBounds(0, 0, 500, 500);
        panelLag.setLayer(opsæt, 10);
        panelLag.add(hovedPanel);
        hovedPanel.setBounds(0, 0, 500, 500);
        panelLag.setLayer(hovedPanel, 8);
        hovedPanel.setVisible(false);
        panelLag.add(indstilinger);
        indstilinger.setBounds(0, 0, 500, 500);
        panelLag.setLayer(indstilinger, 7);

        javax.swing.GroupLayout oversigtLayout = new javax.swing.GroupLayout(oversigt);
        oversigt.setLayout(oversigtLayout);
        oversigtLayout.setHorizontalGroup(
            oversigtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 500, Short.MAX_VALUE)
        );
        oversigtLayout.setVerticalGroup(
            oversigtLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 500, Short.MAX_VALUE)
        );

        panelLag.add(oversigt);
        oversigt.setBounds(0, 0, 500, 500);
        panelLag.setLayer(oversigt, 6);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(panelLag, javax.swing.GroupLayout.PREFERRED_SIZE, 500, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(panelLag, javax.swing.GroupLayout.PREFERRED_SIZE, 500, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainSkærm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainSkærm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainSkærm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainSkærm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        final MainSkærm screen = new MainSkærm();
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                screen.setVisible(true);
            }

        });
        java.util.Timer timer = new java.util.Timer();

        // creating timer task, timer
        TimerTask tasknew = new TimerTask() {
            @Override
            public void run() {
                if (screen.hovedPanel.isVisible()) {
                    screen.hovedPanel.opdaterDataListe();
                } else if (screen.oversigt.isVisible()) {
                    screen.oversigt.repaint();
                }
            }
        };

        // scheduling the task at interval 100 ms
        timer.schedule(tasknew, 100, 100);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public Grafik.HovedPanel hovedPanel;
    public Grafik.Indstilinger indstilinger;
    public Grafik.LoginPanel loginPanel;
    public Grafik.Opsæt opsæt;
    public Grafik.Oversigt oversigt;
    public javax.swing.JLayeredPane panelLag;
    // End of variables declaration//GEN-END:variables

}
